/**
* Created by wl
* 项目管理>持有中-详情页-项目详情-项目管理人员编辑信息
*/
<template>
    <div :class="{'ca-box': $route.name.includes('add'), 'ca-m-t-28':  $route.name.includes('add'), 'ca-p-20': $route.name.includes('add')}">
        <div class="ca-title">
            <h3>项目管理人员</h3>
            <div class="el-right" v-show="showBtn">
                <el-button type="primary" @click="save" size="small">保存</el-button>
                <el-button @click="close" size="small">取消</el-button>
            </div>
        </div>
        <table class="ca-table ca-m-t-15">
            <tr>
                <th>外派董事</th>
                <th>外派监事</th>
                <th>外派高管</th>
                <th>外派高管职位</th>
            </tr>
            <tr>
                <td v-for="(item, index) in itemHoldManagerEntitys" :key="index">
                    <el-input placeholder="请输入内容" v-model="itemHoldManagerEntitys[index].userId" :maxlength="100"></el-input>
                </td>
            </tr>
        </table>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        data() {
            return {
                value: '',
                itemHoldManagerEntitys: [],
            }
        },
        watch: {
            // 深度 watcher
            itemHoldManagerEntitys: {
                handler: function (itemHoldManagerEntitys) {
                    this.$emit('managerInfo', itemHoldManagerEntitys);
                },
                deep: true
            }
        },
        props: {
            showBtn: {
                type: Boolean,
                default: function () {
                    return false;
                }
            },
        },
        mounted() {
            if (this.$route.params.itemId !== '-1' && this.$route.name.includes('add') === false) {
                this.getInfo()
            } else if (this.$route.name.includes('add') === true || this.$route.params.itemId === '-1') {
                this.itemHoldManagerEntitys = []
                for (var j = 2; j < 6; j++) {
                    this.itemHoldManagerEntitys.push({
                        id: null, //id
                        itemId: null, //项目ID
                        userId: '', //管理人员 有可能存 人名
                        userType: Number(this.$store.state.user.dictionaryMap.holdManagerType[j].id) //管理人员类型-外派高管
                    })
                }
            }
        },
        methods: {
            close() {
                this.$emit('close')
            },
            // 获取信息
            getInfo() {
                apiHttp(api.CHECK_MANAGER, {itemId: this.$route.params.itemId}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.itemHoldManagerEntitys = []
                        for (var i = 2; i < 6; i++) {
                            this.itemHoldManagerEntitys.push({
                                id: null, //id
                                itemId: null, //项目ID
                                userId: '', //管理人员 有可能存 人名
                                userType: Number(this.$store.state.user.dictionaryMap.holdManagerType[i].id) //管理人员类型-外派高管
                            })
                        }
                        if (ret.data.itemHoldManagerEntitys.length > 0) {
                            ret.data.itemHoldManagerEntitys.map((item) => {
                                this.itemHoldManagerEntitys.map((val,ind) => {
                                    if (item.userType === val.userType) {
                                        this.itemHoldManagerEntitys[ind] = item
                                    }
                                })
                            })
                        } else {
                            this.itemHoldManagerEntitys = []
                        }
                    }
                })
            },
            // 修改信息
            save() {
                apiHttp(api.EDIT_MANAGER, {itemId: this.$route.params.itemId, itemHoldManagerEntitys: this.itemHoldManagerEntitys}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '修改成功！',
                            type: 'success',
                            center: true
                        });
                        this.$emit('save')
                    }
                })
            },
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.el-right {
    float: right;
}
</style>
